package com.lzx.iteam.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.lzx.iteam.R;
import com.lzx.iteam.bean.CRMTextBean;

import java.util.ArrayList;

import static com.baidu.location.f.mC;
import static com.lzx.iteam.MainActivity.mActivity;

/**
 * Created with IntelliJ IDEA.
 * **********************************
 * User: zhangshuai
 * Date: 2016年 08月 03日
 * Time: 下午1:52
 *
 * @QQ : 1234567890
 * **********************************
 */
public class CRMTextAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<CRMTextBean> mListData;
    private LayoutInflater mInflater;
    private int mIndex;

    public CRMTextAdapter(Context mContext, ArrayList<CRMTextBean> mListData) {
        this.mContext = mContext;
        this.mListData = mListData;
        mInflater = LayoutInflater.from(mContext);
    }

    public void updateView(int index){
        this.mIndex = index;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mListData.size();
    }

    @Override
    public Object getItem(int position) {
        return mListData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.weekly_date_item_layout,null);
            holder.text = (TextView) convertView.findViewById(R.id.tv_weekly_date);
            holder.image = (ImageView) convertView.findViewById(R.id.iv_weekly_select);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.text.setText(mListData.get(position).getContent());
        if (mIndex == position){
            holder.image.setVisibility(View.VISIBLE);
            holder.text.setTextColor(mActivity.getResources().getColor(R.color.weekly_main_orange_line));
        }else{
            holder.image.setVisibility(View.GONE);
            holder.text.setTextColor(mActivity.getResources().getColor(R.color.schedule_content));
        }
        return convertView;
    }

    class ViewHolder{
        private TextView text;
        private ImageView image;
    }
}
